﻿Imports System.Data.OleDb

Public Class AddNewEntry
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_submit.Click
        If f_image.HasFile Then
            f_image.SaveAs(Request.MapPath("Pictures") & "/" & f_image.FileName)
        End If
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringList").ConnectionString)
        Dim sqlString As String = "INSERT INTO SmartPhoneList(Image,CompanyName,ModelNumber,Colors,Author,Title,Description) VALUES(@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        'Dim sqlString As String = "INSERT INTO SmartPhoneList(Image,CompanyName,ModelNumber,Colors,Author,Title,Description) VALUES('/Pictures/TestDeviceFilter.jpg' , 'test' , 'test' , 'test', 'test' , 'test' , 'test')"
        Dim cmd As New OleDbCommand(sqlString, oleDbConn)
        oleDbConn.Open()
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", "Pictures/" & f_image.FileName)
        cmd.Parameters.AddWithValue("@f2", tb_companyname.Text)
        cmd.Parameters.AddWithValue("@f3", tb_modelnumber.Text)
        cmd.Parameters.AddWithValue("@f4", tb_color.Text)
        cmd.Parameters.AddWithValue("@f5", tb_author.Text)
        cmd.Parameters.AddWithValue("@f6", tb_title.Text)
        cmd.Parameters.AddWithValue("@f7", tb_description.Text)
        cmd.ExecuteNonQuery()
        oleDbConn.Close()
        Response.Redirect("default.aspx")
    End Sub
End Class